using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using System.Windows.Forms;


namespace OrderMachine
{
    public class TradeOrde
    {
        [DllImport(@"C:\JihSun\HTS2\Dll\HTSAPITradeClient.dll")]

        static extern void HTSOrder([MarshalAs(UnmanagedType.LPStr)] String msg);
        string dllPath;// = Path.GetDirectoryName(typeof(TradeOrder).Assembly.Location);


        public bool PlaceOrder(int orderDate, int orderTime, bool buy, int Lot, bool LimitOrder, int Price)
        {
            string msg;
            int contractDate;

            msg = "Market=F,";
            msg += "Account= ,";
            msg += "ContractName= TXF ,";
            //msg += "ContractDate=" + contractDate + ",";
            msg += "d";

            return true;
        }

        private int GetContractDate(int orderDate)
        {
            int currentDay = Convert.ToInt32(orderDate.ToString().Substring(5, 2));
            int currentMonth = Convert.ToInt32(orderDate.ToString().Substring(3, 2));
            int currentYear = Convert.ToInt32("20" + orderDate.ToString().Substring(1, 2));

            DateTime dt;
            int Wedcounter = 0;
            bool exchangeMonth;

            for (int i = 1; i <= currentDay; i++)
            {
                dt = new DateTime(currentYear, currentMonth, currentDay);
                if (dt.DayOfWeek == DayOfWeek.Wednesday)
                    Wedcounter++;

                bool MatchCondition = (dt.DayOfWeek == DayOfWeek.Monday) || (dt.DayOfWeek == DayOfWeek.Tuesday) || Wedcounter > 2;

                if (Wedcounter > 1 && MatchCondition)
                {
                    exchangeMonth = true;
                    break;
                }
            }

            return 0;

        }

        public void TESTG(int G)
        {
            TextWriter tw = new StreamWriter(@"c:\GTest.txt");
            tw.WriteLine(DateTime.Now);

            tw.Close();
        }
    }
}